const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
		statusList:[
			{id: '', label: '不限'}, 
			{id: 1, label: '初筛'}, 
			{id: 2, label: '感兴趣'}, 
			{id: 3, label: '不感兴趣'}, 
			{id: 4, label: '邀面试'}, 
			{id: 5, label: '待查阅'}
		],
		statusId:'',
		industryArr:[],
		industryId:'',
		workYears:[],
		workYearsId: '',
		xueliArr:[],//学历
		xueliId:'',//学历
		
		ageList: [
			{ id: '', label: '不限' },
			{ id: 1, label: '18-25' },
			{ id: 2, label: '26-35' },
			{ id: 3, label: '36-45' },
			{ id: 4, label: '46-55' },
			{ id: 5, label: '55以上' },
		],
		ageId: '',
		searchForm:{
			ageBegin: "",
      ageEnd: "",
      applyState: "",
      createTime: "",
      educational: "",
      experience: "",
		},
  },

  onLoad: function (options) {
		this.cacheForm = {...this.data.searchForm}
		let cacheFilter = wx.getStorageSync('jl_filter')
		this.setData({
			...cacheFilter
		})
		this.getWorkYears()
		this.getXueLi()
	},
	
	
	// 所属行业 选择
	onStatusChange(e){
		let { id, name } = e.currentTarget.dataset
		this.data.searchForm.applyState = id
		this.setData({ statusId:id })
	},

	getWorkYears(){
		let _this = this
		wx.request({
			url: url + 'dict/getWorkYearState',
			method:'get',
			data: {},
			success: function(res){
				_this.setData({
					workYears: res.data.data,
				})
			},
			fail:function(res){
				console.log(res)
			}
		})
	},
	onWorkYearChange(e){
		let { id, name } = e.currentTarget.dataset

		// let begin = '', end = ''
		if(name == '不限') {
			this.data.searchForm.experience = ''
		} else {
			this.data.searchForm.experience = name
			// begin = parseInt(name.split('-')[0])
			// end = parseInt(name.split('-')[1])
			// begin = isNaN(begin) ? '' : begin
			// end = isNaN(end) ? '' : end
		}
		// this.data.searchForm.experienceBegin = begin
			// this.data.searchForm.experienceEnd = end
		console.log('工作经验',	this.data.searchForm.experience)
		this.setData({ workYearsId:id })
	},
	getXueLi(){
		let _this = this
		wx.request({
			url: url + 'dict/getEducationState',
			method:'get',
			data: {},
			success: function(res){
				_this.setData({
					xueliArr:res.data.data,
				})
			},
			fail:function(res){
				console.log(res)
			}
		})
	},
	//学历
	xuelixueli(e){
		let { id, name } = e.currentTarget.dataset
		if(name == '不限') {
			this.data.searchForm.educational = ''
		} else {
			this.data.searchForm.educational = name
		}
		this.setData({ xueliId:id})
	},
	
	onAgeChange(e){
		let {id, name} = e.currentTarget.dataset
		let ageBegin = '', ageEnd = ''
		ageBegin = parseInt(name.split('-')[0])
		ageEnd = parseInt(name.split('-')[1])
		ageBegin = isNaN(ageBegin) ? '' : ageBegin
		ageEnd = isNaN(ageEnd) ? '' : ageEnd
		this.data.searchForm.ageBegin = ageBegin
		this.data.searchForm.ageEnd = ageEnd
		this.setData({
			ageId: id
		})
	},

	
	reset(){
		this.setData({
			searchForm: {...this.cacheForm},
			statusId: '',
			workYearsId:'',
			xueliId: '',
			ageId: ''
		})
		wx.removeStorage('jl_search')
	},
	submit(){
		wx.setStorageSync('jl_search', this.data.searchForm)
		let cacheFilter = {
			statusId: this.data.statusId,
			workYearsId: this.data.workYearsId,
			xueliId: this.data.xueliId,
			ageId: this.data.ageId
		}
		wx.setStorageSync('jl_filter', cacheFilter)
		let pages = getCurrentPages();//当前页面栈
		let prePage = pages[pages.length - 2]
		prePage.reload()
		wx.navigateBack()
	},





})